package com.qf.service;

import com.qf.mapper.UserMapper;
import com.qf.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 孙亚梅
 * @version V1.0
 * @Project javase2203
 * @Package com.qf.service
 * @Description:
 * @Date 2022/6/6 22:32
 */
@Service("service1")
public class UserServiceImpl implements  UserService {


    //需要被注入的用户dao全局对象
    @Autowired
    private UserMapper userMapper;

    //从jdbc.properties文件中根据key拿value值
    @Value("${jdbc.url}")
    private String url;

    @Value("${jdbc.username}")
    private String username;

    public List<User> findAll() {

        System.out.println("=====url======" + url);
        System.out.println("=====username======" + username);

        //直接用注入的UserMapper对象
        List<User> list = userMapper.findUserAll();
        return list;


    }
    @Override
    @Transactional
    public void updateUser(User user) {
        userMapper.updateUser(user);

        //演示在拥有事务的操作中，如果出现异常，是否会回滚
    int i= 1/0;
    }
}
